/**
 * 
 */
package com.cwnuzj.ffms.ui.view.navigation;

import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import com.cwnuzj.ffms.model.navigation.Category;
import com.cwnuzj.ffms.model.navigation.TreeNodeObject;
import com.cwnuzj.ffms.util.CacheImage;

/**
 * @author Jeff Zheng
 */
public class NavViewLabelProvider extends StyledCellLabelProvider {
	@Override
	public void update(ViewerCell cell) {
		Object element = cell.getElement();
		StyledString text = new StyledString();

		if (element instanceof Category) {
			Category category = (Category) element;
			text.append(category.getName());
			if("收支".equalsIgnoreCase(category.getName())){
				cell.setImage(CacheImage.getINSTANCE().getImage("icons/action/image_multi.png"));
			}
			if("设置".equalsIgnoreCase(category.getName())){
				cell.setImage(CacheImage.getINSTANCE().getImage("icons/action/cog.png"));
			}
			text.append("(" + category.getNodes().size() + ")", StyledString.COUNTER_STYLER);
		} else {
			TreeNodeObject node = (TreeNodeObject) element;
			text.append(node.getName());
			cell.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE));
		}
		cell.setText(text.toString());
		cell.setStyleRanges(text.getStyleRanges());
		super.update(cell);
	}

}
